package edu.byu.intex2.data.bo;

import edu.byu.intex2.data.DataException;
import edu.byu.intex2.data.dao.*;

/**
 * @author Jason Whiting
 */
public class PartServiceLine extends BusinessObject
{

    private int quantityUsed;
    private String serviceId;
    private String taskId;
    private String partId;
    private Part part;
    private ServiceLine serviceLine;
    /** psf */
    private PartsAtServiceFacility psf;

    /**
     * Creates a new instance of BusinessObject
     * @param id
     */
    public PartServiceLine(String id)
    {
        super(id);
    }//constructor

    //Quick Access Method
    public void save() throws DataException
    {
        try
        {
            PartServiceLineDAO.getInstance().save(this);
        } catch (DataException e)
        {
            e.printStackTrace();
        }
    }

    /**
     * @return the quantityUsed
     */
    public int getQuantityUsed()
    {
        return quantityUsed;
    }

    /**
     * @param quantityUsed the quantityUsed to set
     */
    public void setQuantityUsed(int quantityUsed)
    {
        this.quantityUsed = quantityUsed;
        this.setDirty();
    }

    /**
     * @return the serviceId
     */
    public String getServiceId()
    {
        return serviceId;
    }

    /**
     * @param serviceId the serviceId to set
     */
    public void setServiceId(String serviceId)
    {
        this.serviceId = serviceId;
        this.setDirty();
    }

    /**
     * @return the taskId
     */
    public String getTaskId()
    {
        return taskId;
    }

    /**
     * @param taskId the taskId to set
     */
    public void setTaskId(String taskId)
    {
        this.taskId = taskId;
        this.setDirty();
    }

    /**
     * @return the partId
     */
    public String getPartId()
    {
        return partId;
    }

    /**
     * @param partId the partId to set
     */
    public void setPartId(String partId)
    {
        this.partId = partId;
        this.setDirty();
    }

    /**
     * @return the psf
     */
    public PartsAtServiceFacility getPsf()
    {
        return psf;
    }

    /**
     * @param psf the psf to set
     */
    public void setPsf(PartsAtServiceFacility psf)
    {
        this.psf = psf;
    }

    /**
     * @return the serviceLine
     */
    public ServiceLine getServiceLine()
    {
        return serviceLine;
    }

    /**
     * @param serviceLine the serviceLine to set
     */
    public void setServiceLine(ServiceLine serviceLine)
    {
        this.serviceLine = serviceLine;
    }

    /**
     * @return the part
     */
    public Part getPart()
    {
        if (part == null)
        {
            try
            {
                part = PartDAO.getInstance().read(partId);
            } catch (Exception e)
            {
                e.printStackTrace();
            }
        }
        return part;
    }

    /**
     * @param part the part to set
     */
    public void setPart(Part part)
    {
        this.part = part;
        setPartId(part.getId());
    }

    @Override
    public String toString()
    {
        return quantityUsed + " - " + getPart().getName() + " - $" + getPart().getPrice();
    }
}
